package com.lc.admin.utils;

import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

public class RequestUtils {

    /**
     * 接收web层的参数列表，把参数列表转换成?参数1=值1&参数2=值2&参数3=值3
     * @param params
     * @return
     */
    public static String paramsBuild(Map<String,Object> params) {
        boolean first = false;
        StringBuilder sb = new StringBuilder("");
        for (String key : params.keySet()) {
            String value = params.get(key).toString();

            if(StringUtils.isNotEmpty(value)) {
                if(first) {
                    sb.append("&"+key+"="+value);
                    continue;
                }
                sb.append("?"+key+"="+value);
                first = true;
            }
        }
        return  sb.toString();
    }

    public static void main(String[] args) {
        Map<String,Object> params = new HashMap<>();
        System.out.println(paramsBuild(params));
    }
}
